package com.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.model.UsersPersonal;
import com.service.UsersPersonalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 个人信息表  前端控制器
 * </p>
 *
 * @author Damon
 * @since 2021-04-30
 */
@RestController
@RequestMapping("/personal")
public class UsersPersonalController {
    @Autowired
    private UsersPersonalService usersPersonalService;

    @RequestMapping("/listAll")
    public List<UsersPersonal> listAll(){ return usersPersonalService.list();
    }

    @RequestMapping("/list")
    public Page<UsersPersonal> list(String  companyS, Long pageNum, Long size){
        Page<UsersPersonal> page = new Page<>(pageNum, size);
        page = usersPersonalService.listPage(page,new UsersPersonal(companyS));
        return page;
    }

    @RequestMapping("/listP")
    public Page<UsersPersonal> listP(String  companyS, Long pageNum, Long size){
        Page<UsersPersonal> page = new Page<>(pageNum, size);
        page = usersPersonalService.listPageP1(page,new UsersPersonal(companyS));
        return page;
    }

    @RequestMapping("/listE")
    public Page<UsersPersonal> listE(String  companyS, Long pageNum, Long size){
        Page<UsersPersonal> page = new Page<>(pageNum, size);
        page = usersPersonalService.listPageE1(page,new UsersPersonal(companyS));
        return page;
    }

    @RequestMapping("/del")
    public boolean del(UsersPersonal usersPersonal){
        usersPersonal = usersPersonalService.getById(usersPersonal.getId());
        usersPersonal.setIsdelete(1);
        usersPersonalService.updateById(usersPersonal);
        return true;
    }

    @RequestMapping("/edit")
    public boolean edit(@RequestBody UsersPersonal usersPersonal){
        boolean res = false;
        if("0".equals(usersPersonal.getModify())){
            //新增
            res =usersPersonalService.save(usersPersonal);
        }else{
            //修改
            if (0 == usersPersonal.getIsdelete()) {
                res =usersPersonalService.updateById(usersPersonal);
            } else {
                return false;
            }
        }
        return res;
    }

    @RequestMapping("/getById")
    public UsersPersonal getById(String id){
        return usersPersonalService.getById(id);
    }

}

